#include "array_sentinel.h"

#define SENTINELLE '\0'

void set__empty(char * s)
{
  s[0] = SENTINELLE;
}

size_t set__size(const char * s)
{
  assert(s != NULL);

  size_t size;
	
  for(size = 0; s[size] != SENTINELLE; size++)
    ;

  return size;
}

int set__add(char * s, char c)
{
  assert(s != NULL);

  int size = set__size(s);
  
  if(set__find(s, c))
    {
      set__errno = SET__ELEMENT_DUPLICATION;
      return 1;
    }
  
  if(size + 1 >= SET__SIZE)
    {
      set__errno = SET__CAPACITY_EXCEEDED;
      return 1;
    }
  
  set__errno = 0;
  
  s[size] = c;
  s[size + 1] = SENTINELLE;
  
  return 0;
}

//~ int set__remove(char * s, char c)
//~ {
	//~ 
//~ }
//~ 
//~ int set__is_empty(const char * s)
//~ {
	//~ 
//~ }

int set__find(const char * s, char c)
{
  int index;
  for(index = 0; s[index] != SENTINELLE; index++)
    if(s[index] == c)
      return 1;
  
  return 0;
}

//~ int set__inter(const char * s1, const char * s2, char * si)
//~ {
	//~ 
//~ }
//~ 
//~ int set__union(const char * s1, const char * s2, char * su)
//~ {
	//~ 
//~ }
